import {getCourseRecord} from '../../../api/teacher/course'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    postData:{
      pageNum:1,
      pageSize:10
    },
   courseRecordList:[],
   total:0, //总页数
   moreLimt:false,//是否加载完成
   isfreshComplete:false, //是否刷新完成
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    this.requireCourseList()
  },
      // 列表刷新课程
      loadPageEvent(data:any){
        const type = data.detail.type
        switch(type){
          case 'refresh':
            this.resetPage()
            this.requireCourseList()
            this.setData({
              isfreshComplete:true
            })
            break;
           case 'load':
            let postData = this.data.postData as any
            if(postData.pageNum * postData.pageSize < this.data.total){
              postData.pageNum  = postData.pageNum + 1
              this.setData({
                postData
              })
              this.requireCourseList()
            }else{
             this.setData({
              moreLimt: true
             })
            }
            break;
        }
        },
                // 重置页码
    resetPage(){
      let postData = this.data.postData as any
        postData.pageNum = 1
     this.setData({
      postData,
      courseRecordList:[]
     })
    },
//  获取上课记录
 async requireCourseList(){
  try {
    const postData = this.data.postData as any
   const {code,data:res} = await getCourseRecord(postData)
   if(code === 200){
     const {list,total} = res
     const courseRecordList = this.data.courseRecordList.concat(list)
     this.setData({
      courseRecordList,
      total
     })
   }
  } catch (error) {
    
  }
 },
 courseDetail(e:any){
  wx.navigateTo({
    url:`/teacher_course_package/pages/teacherCourseDetail/teacherCourseDetail?lessonId=${e.currentTarget.dataset.id}&title=${e.currentTarget.dataset.title}`
  })
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})